<template>
	<view class="flex-col page">
		<view>
			<view :style="{height:statusBarHeight+'px'}"></view>
			<u-navbar title="线下商家" bgColor="#F5F5F5" @leftClick="$nav(2)">	
			</u-navbar>
		</view>
		
		<view class="header">
		    <view class="search-box" @click="$nav(1,'/pages/merchant/merchant_search')">
		        <image class="img" :src="staticResource('home/custom/search.png')" />
		        <view class="input">搜索商家</view>
		    </view>
		</view>
		
		<view class="banner-ad">
		    <uni-swiper-dot :info="banner" :current="current" bottom="-10" field="content" mode="round">
		        <swiper 
		            class="swiper" 
		            autoplay 
		            :duration="300" 
		            :interval="5000" 
		            :indicator-dots="false" 
		            circular
		            @change="onChange">
		            <swiper-item v-for="(item, idx) in banner" :key="idx">
		                <image class="banner-ad-img" :src="item.image_url" mode="aspectFill"/>
		            </swiper-item>
		        </swiper>
		    </uni-swiper-dot>
		</view>
		
		<view>
			 <scrollX :list="categoryList" :nums="5" :col="2" />
		</view>
		
		<view v-if="list.length > 0" class="flex-col" style="margin-top: 10rpx;background-color: #fff;">
			<view class="category-bg">
				<view class="item"  v-for="(cItem,index) in list" :key="index">
					
					<view class="flex-row" @click="ppClick(cItem)">
						<image :src="cItem.brand_img" style="width: 100rpx;height: 100rpx;border-radius: 6rpx;"></image>
						<view class="flex-col" style="margin-left: 15rpx;">
							<text>{{cItem.name}}</text>
							<view class="item_tag">{{cItem.category_name}}</view>
						</view>
					</view>
					
				</view>
			</view>
			
			<u-loadmore margin-top="20" margin-bottom="20" :status="status" icon-type="flower"
				:load-text="loadText" />
		</view>
		
		<view v-else class="flex-col items-center" style="margin-top: 80rpx;">
			<image src="/static/data_empty.png"></image>
			<text style="color: #c0c4cc;">暂无数据</text>
		</view>
	</view>
</template>

<script>
	import scrollX from '@/components/category-list.vue'
	export default {
		data() {
			return {
				categoryList:[],
				page:1,
				status: 'loadmore',
				loadText: {
					loadmore: '下拉加载更多...',
					loading: '加载中...',
					nomore: '没有更多数据了...'
				},
				list:[],
				banner:[]
			};
		},
		components: {
			scrollX
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight + 44
			}
		},
		onLoad() {
			this.getMerchantCategory();
			this.getBanner();
			this.list = [];
			this.page = 1;
			this.getMerchantList();
		},
		onPullDownRefresh() {
			this.list = [];
			this.page = 1;
			this.getMerchantList();
		},
		onReachBottom() {
			this.getMerchantList();
		},
		methods:{
			getBanner(){
				this.$request({
					url:'?c=Index&a=carousel',
					type:'post',
					data:{
						identification:'xjsj'
					}
				}).then(res =>{
					this.banner = res.data;
				});
			},
			ppClick(item){
				let obj = JSON.stringify(item)
				uni.navigateTo({
					url: '/pages/merchant/merchant_make?obj=' + obj
				})
			},
			
			itemClick(item){
				uni.navigateTo({
					url:'/pages/merchant/merchant_detail?id='+item.merchant_id + '&title='+item.merchant_name
				});
			},
			getMerchantList(){
				this.$request({
					url:'?c=MerchantOffline&a=merchantMakeList',
					type:'post',
					data:{
						page:this.page,
						limit:10
					}
				}).then(res =>{
					uni.stopPullDownRefresh();
					this.status = 'loadmore';
					if (res.data && res.data.length > 0) {
						this.list = [...this.list, ...res.data];
						this.page += 1;
						if (res.data.length < 10) {
							this.status = 'nomore';
						}
					} else {
						this.status = 'nomore';
					}
				})
			},
			getMerchantCategory(){
				this.$request({
					url:'?c=MerchantOffline&a=merchantCategoryList',
					type:'post',
				}).then(res =>{
					this.categoryList = res.data;
				})
			},
			staticResource(path){
				return "https://ysmz.scmzhc.com/static/mini/images/"+path;
			},
		}
	}
</script>

<style lang="scss">
.page{
	width: 100%;
	overflow-y: auto;
	overflow-x: hidden;
	height: 100%;
}
.category-bg{
	display: flex;
	flex-wrap: wrap;
	// background-color: #fff;
	padding-bottom: 30rpx;
}
.item{
	display: flex;
	flex-direction: column;
	// align-items: center;
	flex: 0 0 50%;
	padding-left: 40rpx;
	margin-top: 50rpx;
}
.m-item{
	width: 100%;
	background-color: #fff;
	padding: 20rpx;
}
.left{
	display: flex;
	flex-direction: row;
	// justify-content: flex-start;
	width: 80%;
	.img{
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}
	.name-text{
		margin-left: 15rpx;
		width: 100%;
	    flex: 1;
	}
}
.right{
	display: flex;
	width: 20%;
	text-align: center;
	justify-content: flex-end;
	margin-right: 20rpx;
	font-size: 25rpx;
	color: #999;
}
.line{
	border: 1px solid #f5f5f5;
	// margin-top: 25rpx;
}

.header {
    display: flex;
    align-items: center;
    padding: 20rpx;
    .search-box {
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #ffffff;
        height: 70rpx;
        border-radius: 35rpx;
        flex: 1;
        .img {
            width: 32rpx;
            height: 32rpx;
            margin-left: 24rpx;
            margin-right: 15rpx;
        }
        .input {
            flex: 1;
            text-align: left;
            color: #999999;
            font-size: 28rpx;
        }
    }
}
.banner-ad{
    box-sizing: border-box;
	margin-bottom: 20rpx;
    .swiper{
        width: 100%;
        height: 250rpx;
        // padding: 0 25rpx;
        box-sizing: border-box;
    }
    .banner-ad-img{
        margin: 0 25rpx;
        box-sizing: border-box;
        width: calc(100% - 50rpx);
        height: 100%;
        border-radius: 20rpx;
        background-color: gray;
        box-shadow: 0rpx 5rpx 18rpx 2rpx rgba(90,115,241,0.44);
    }
}
.item_tag{
	background-color: #f7d4c6;
	font-size: 22rpx;
	border-radius: 6rpx;
	color: #c6615d;
	text-align: center;
	margin-top: 6rpx;
}
</style>
